How to create a href link that will act like a button?
How to create a href link that will act like a button?
26329-Aug-2023
Updated on 02-Sep-2023
Home / DeveloperSection / Forums / How to create a href link that will act like a button?
How to create a href link that will act like a button?
Aryan Kumar
02-Sep-2023To create a
<a>
tag that will behave like a button, you can set itstype
attribute tobutton
. This will tell the browser to render the link as a button, rather than as a regular hyperlink.For example, the following code will create a link that will behave like a button:
HTML
You can also style the button using CSS. For example, the following CSS code will style the button to have a blue background and white text:
CSS
In this code, the
a.button
selector is used to select all links with thetype
attribute set tobutton
. Thebackground-color
property is set to blue, thecolor
property is set to white, thepadding
property is set to 10px 20px, and theborder-radius
property is set to 5px.Here are some additional things to keep in mind when creating a
<a>
tag that will behave like a button:href
attribute is still required, even though the link will not actually navigate to the specified URL.target
attribute can be used to specify the target window or frame for the link.onclick
attribute can be used to specify an event handler that will be triggered when the button is clicked.